/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bl;

import entity.LeaveDetail;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JLabel;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Kien Chinh
 */
public class ModelTableCancelLeave extends AbstractTableModel {

    ArrayList<LeaveDetail> list;
    private final static int STT = 0;
    private final static int LEAVETYPE = 1;
    private final static int STARTDATE = 2;
    private final static int ENDDATE = 3;
    private final static int ISAPPROVED = 4;
    private final static int RESON = 5;
    private final static int CAUSE = 6;
    private final static int CANCEL = 7;
    private String[] ColumnName = {"No.", "Leave Type", "From date", "To date", "is Approved", "Reson to leave","Cause to cancel leave", "#"};

    public ModelTableCancelLeave(ArrayList<LeaveDetail> list) {
        this.list = list;
    }

    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return ColumnName.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        LeaveDetail detail = list.get(rowIndex);
        switch (columnIndex) {
            case STT:
                return rowIndex + 1;
            case LEAVETYPE:
                return detail.getType().getName();
            case STARTDATE:
                return detail.getStartLeave();
            case ENDDATE:
                return detail.getFinishLeave();
            case ISAPPROVED:
                switch (detail.getStatus()) {
                    case 0:
                        return new JLabel("Approved");
                    case 3 :
                        return new JLabel("Cancel");
                    default:
                        return new JLabel("Pending");
                }
            case RESON:
                return detail.getReson();
            case CANCEL:
                return new JLabel("        Cancel Leave");
            case CAUSE :
                return detail.getCause();
            default:
                return new Object();
        }
    }

    @Override
    public Class getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case STT:
                return Integer.class;
            case LEAVETYPE:
                return String.class;
            case STARTDATE:
                return Date.class;
            case ENDDATE:
                return Date.class;
            case ISAPPROVED:
                return JLabel.class;
            case RESON:
                return String.class;
            case CANCEL:
                return JLabel.class;
            case CAUSE :
                return String.class;
            default:
                return Object.class;
        }
    }

    @Override
    public String getColumnName(int columnIndex) {
        return ColumnName[columnIndex];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }
}
